package com.song.util;

import com.song.config.CustomUserDetails;
import com.song.pojo.UserModel;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author slh
 * @version 1.0
 * @date 2020/5/5 下午12:00
 */
public class UserLoginInfo {

    public static String getUId() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();


        if (principal instanceof UserModel) {
            return ((UserModel) principal).getId();
        } else if (principal instanceof CustomUserDetails) {
            return ((CustomUserDetails) principal).getId();
        }

        return "";
    }

    public static String getName() {
        Authentication principal = SecurityContextHolder.getContext().getAuthentication();

        return principal.getName();
    }
}
